package hot100;

public class removeNthFromEnd2 {
    public mergeKLists.ListNode removeNthFromEnd(mergeKLists.ListNode head, int n) {
        mergeKLists.ListNode ret = new mergeKLists.ListNode(0);
        ret.next = head;
        mergeKLists.ListNode slow = ret;
        mergeKLists.ListNode fast = head;
        while(n > 0) {
            fast = fast.next;
            n--;
        }
        while(fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        slow.next = slow.next.next;
        return ret.next;
    }
}
